home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’95 / Menu Controls / UShapes.h < prev    next >
Encoding:
Text File  |  1995-06-24  |  5.3 KB  |  184 lines  |  [TEXT/MPS ]

  1. // Copyright © 1994-95 by Apple Computer, Inc. All rights reserved.
  2. // UShapes.h
  3.  
  4. #ifndef __USHAPES__
  5. #define __USHAPES__
  6.  
  7. #ifndef __UOBJECT__
  8. #include <UObject.h>
  9. #endif
  10.  
  11. #ifndef __GEOMETRY__
  12. #include "Geometry.h"
  13. #endif
  14.  
  15. #ifndef __TOOLBOX__
  16. #include "Toolbox.h"
  17. #endif
  18.  
  19. //--------------------------------------------------------------------------------------------------
  20.  
  21. class TFile;
  22. class TShapeView;
  23. class TView;
  24.  
  25. //--------------------------------------------------------------------------------------------------
  26. // Constants
  27.  
  28. // Shape ids
  29. const short IDBox            = 1;
  30. const short IDCircle        = 2;
  31. const short IDhBox            = 3;
  32. const short IDTextShape        = 4;
  33.  
  34. //--------------------------------------------------------------------------------------------------
  35. // ShapeData: Information about a single shape;
  36. //                same format used both in the data file and in the desk scrap.
  37.  
  38.     struct ShapeData {
  39.         short        theId;                // 1 = rectangle; 2 = oval; etc.
  40.         CRect        theRect;            // the shape's extent
  41.         short        thePattern;            // the shape's current Pattern
  42.         CRGBColor    theColor;            // the shape's current color
  43.         Boolean        theSelected;        // for saving window state; not relevant for clipboard
  44.         };
  45.  
  46.     typedef ShapeData* ShapeDataPtr;
  47.  
  48. //--------------------------------------------------------------------------------------------------
  49. // CLASS TShape - abstract class
  50. //--------------------------------------------------------------------------------------------------
  51. class TShape : public TObject
  52. {
  53.     MA_DECLARE_CLASS;
  54.  
  55.   public:
  56.     TShape();        // Constructor
  57.  
  58.     void IShape(const CRect& itsFrame, short itsID);
  59.         // Initialze a shape procedurally
  60.     
  61.     virtual void DoInitialState(TShapeView* itsView);
  62.  
  63.     // • I/O
  64.     virtual void ReadFrom(TStream* aStream);    // Override
  65.     virtual void WriteTo(TStream* aStream);        // Override
  66.  
  67.     // • Screen display
  68.     virtual void Draw();
  69.     virtual void DrawOutline();
  70.     virtual void Highlight(HLState fromHL, HLState toHL, TView* itsView);
  71.  
  72.     // • Misc
  73.     inline void GetColor(CRGBColor& itsColor) { itsColor = fColor; }
  74.     inline short GetID() { return fIdentifier; };
  75.         // Used so that a filed shape can identify what kind of shape object is
  76.         // to be instantiated to represent it in memory
  77.     inline short GetPattern() { return fPattern; };
  78.     inline void ReplacePattern(short newPattern)
  79.         { fOldPattern = fPattern;
  80.           fPattern = newPattern;
  81.         };
  82.     inline void ReplaceColor(CRGBColor newColor)
  83.         { fOldColor = fColor;
  84.           fColor = newColor;
  85.         };
  86.  
  87.     inline Boolean WasSelected() { return fWasSelected; };
  88.     inline Boolean IsSelected() { return fIsSelected; };
  89.     inline void SetSelected(Boolean isSelected) { fIsSelected = isSelected; };
  90.     inline void SetWasSelected(Boolean wasSelected) { fWasSelected = wasSelected; };
  91.     inline void SetIsWasSelected() { fIsSelected = fWasSelected; };
  92.     inline void SetWasIsSelected() { fWasSelected = fIsSelected; };
  93.  
  94.     void SetFields(short pattern, CRGBColor color, CRect extentRect);
  95.         // Used to initialize shapes created from the Clipboard
  96.     
  97.     void GetFrame(CRect& itsFrame);
  98.     virtual void SetFrame(const CRect& extentRect);
  99.  
  100.     virtual void BeInView(TShapeView* itsView);
  101.  
  102.     short        fPattern;                    // Pattern of object
  103.     short        fOldPattern;                // old shade, for Reshade command Undo/Redo
  104.     CRGBColor    fColor;                        // color of object
  105.     CRGBColor    fOldColor;                    // old color, for Recolor command Undo/Redo
  106.  
  107.   protected:
  108.     CPoint        fLocation;
  109.     CPoint        fSize;
  110.     short        fIdentifier;
  111.     Boolean        fIsSelected;                // is shape selected?
  112.     Boolean        fWasSelected;                // old selection status, set when last command was performed
  113. };
  114.  
  115. //--------------------------------------------------------------------------------------------------
  116. // CLASS TArrowTool
  117. //--------------------------------------------------------------------------------------------------
  118. class TArrowTool : public TShape
  119. {
  120.     MA_DECLARE_CLASS;
  121.  
  122.   public:
  123.     TArrowTool();
  124.     void IArrowTool(CRect itsExtent, short itsID);
  125.  
  126.     virtual void Draw();        // Override
  127.  
  128.   protected:
  129.     BitMap        fArwBitMap;                // bitmap used to draw arrow in palette
  130.  
  131. };
  132.  
  133. //--------------------------------------------------------------------------------------------------
  134. // CLASS TBox
  135. //--------------------------------------------------------------------------------------------------
  136. class TBox : public TShape
  137. {
  138.     MA_DECLARE_CLASS;
  139.  
  140.   public:
  141.     TBox();
  142.     void IBox(CRect itsExtent, short itsID);
  143.  
  144.     virtual void Draw();        // Override
  145.     virtual void DrawOutline();    // Override
  146. };
  147.  
  148. //--------------------------------------------------------------------------------------------------
  149. // CLASS THeavyBox - like a TBox except uses up 4K bytes
  150. //--------------------------------------------------------------------------------------------------
  151. class THeavyBox : public TBox
  152. {
  153.     MA_DECLARE_CLASS;
  154.  
  155.   public:
  156.     THeavyBox();
  157.     void IHeavyBox(CRect itsExtent, short itsID);
  158.  
  159.     virtual void ReadFrom(TStream* aStream);    // Override
  160.     virtual void WriteTo(TStream* aStream);        // Override
  161.  
  162.     virtual void Draw();        // Override
  163.  
  164.   private:
  165.     long    fFiller[1024];
  166. };
  167.  
  168. //--------------------------------------------------------------------------------------------------
  169. // CLASS TCircle
  170. //--------------------------------------------------------------------------------------------------
  171. class TCircle : public TShape
  172. {
  173.     MA_DECLARE_CLASS;
  174.  
  175.   public:
  176.     TCircle();
  177.     void ICircle(CRect itsExtent, short itsID);
  178.  
  179.     virtual void Draw();        // Override
  180.     virtual void DrawOutline();    // Override
  181. };
  182.  
  183. #endif
  184.